#pragma once

#include "DateTime.h"
#include "InternetAddress.h"
#include "RawData.h"
#include "TimeSpan.h"

namespace Core
{
	enum LogFileIntervals
	{
		LogFileInterval_EverySecond = 0,
		LogFileInterval_EveryMinute = 0,
		LogFileInterval_EveryHour = 0,
		LogFileInterval_EveryDay = 0,
		LogFileInterval_EveryMonth = 0,
		LogFileInterval_EveryYear = 0,
		LogFileInterval_Unlimited
	};

	class LogFileWriter
	{
	private:
		std::string m_FileNameMask;
		std::ofstream* m_FStream;
		DateTime m_FileTime;
		LogFileIntervals m_LogFileInterval;

		void FinalizeFStream();
		bool IsExpired();

	public:
		LogFileWriter();
		~LogFileWriter();
		void SetFileNameMask(std::string p_FileNameMask);
		void SetInterval(LogFileIntervals p_LogFileInterval);
		std::ofstream& GetStream();
		void CheckFileName();
		void WriteRawData(RawData& p_RawData, InternetAddress p_SenderAddress, InternetAddress p_ReceiverAddress, TimeSpan p_TimeSpan = TimeSpan());
	};

	class LogFileReader
	{
	private:
		std::string m_FileName;
		std::ifstream m_FStream;
		unsigned int m_NumberOfRawData;
		DateTime m_EarliestData;
		DateTime m_LatestData;

	public:
		LogFileReader();
		void Open(std::string p_FileName, bool p_Analyze = false);
		void Close();
		bool IsEOF();
		void ReadRawData(RawData& p_RawData, InternetAddress& p_SenderAddress, InternetAddress& p_ReceiverAddress, TimeSpan& p_TimeSpan);
		std::string GetFileName();
		unsigned int GetNumberOfRawData();
		DateTime GetEarliestData();
		DateTime GetLatestData();

	};
}
